package com.luom.springbootinit.controller;

import com.luom.springbootinit.annotation.AuthCheck;
import com.luom.springbootinit.common.BaseResponse;
import com.luom.springbootinit.common.ResultUtils;
import com.luom.springbootinit.constant.UserConstant;
import com.luom.springbootinit.model.vo.BookAnalysisVO;
import com.luom.springbootinit.model.vo.CountAnalysisVO;
import com.luom.springbootinit.model.vo.UserAnalysisVO;
import com.luom.springbootinit.service.BookService;
import com.luom.springbootinit.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 统计接口
 *
 */
@RestController
@RequestMapping("/analysis")
@Slf4j
public class AnalysisController {

    @Resource
    private BookService bookService;

    @Resource
    private UserService userService;

    @GetMapping("/book")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<List<BookAnalysisVO>> getBookAnalysis() {
        List<BookAnalysisVO> bookList = bookService.getTop5Book();
        return ResultUtils.success(bookList);
    }

    @GetMapping("/user")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<List<UserAnalysisVO>> getUserAnalysis() {
        List<UserAnalysisVO> userList = userService.getTop5User();
        return ResultUtils.success(userList);
    }

    @GetMapping("/count")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<CountAnalysisVO> getCountAnalysis() {
       CountAnalysisVO countAnalysisVO=bookService.getCountAnalysis();
        return ResultUtils.success(countAnalysisVO);
    }
}
